package com.fenghongzhang.day008view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class MyCircle extends View {
    int progress;
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    public MyCircle(Context context) {
        super(context);
    }

    public MyCircle(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        paint.setStrokeWidth(10);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLUE);
        //矩形

        RectF rectF = new RectF(200,200,600,600);
        canvas.drawRect(rectF,paint);
        //矩形,起始角度,画多度.是否使用中心点
        canvas.drawArc(rectF,0,progress,false,paint);
        canvas.drawText("4",rectF.centerX(),rectF.centerY(),paint);
    }

    public void start(){
        new Thread(new Runnable() {
            @Override
            public void run() {

                for (int i = 0; i <=360 ; i++) {
                    try {
                        Thread.sleep(20);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    //主线程
//                  invalidate();
                    //子线程
                    progress = i;
                    MyCircle.this.postInvalidate();

                }

            }
        }).start();
    }
}
